package com.tl.commonlibrary.ui.widget;

import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tl.commonlibrary.R;
import com.tl.commonlibrary.tool.DeviceUtil;
import com.tl.commonlibrary.tool.UIUtils;
import com.wang.avi.AVLoadingIndicatorView;

/**
 * Created by a on 2015/11/12.
 */
public class NoDataView extends LinearLayout implements View.OnClickListener {
    private OnNoDataClickListener noDataClickListener;
    private TextView textView;

    public NoDataView(Context context) {
        this(context, null);
    }

    public NoDataView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        setLayoutParams(params);
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        View root = LayoutInflater.from(context).inflate(R.layout.layout_no_data, null);
        textView = root.findViewById(R.id.textView);
        textView.setOnClickListener(this);
        addView(root);

    }
    public void setText(String message){
        if(textView!= null){
            textView.setText(message);
        }
    }
    public void setNoDataClickListener(OnNoDataClickListener noDataClickListener) {
        this.noDataClickListener = noDataClickListener;
    }

    @Override
    public void onClick(View v) {
        if (v == textView) {
            if (noDataClickListener != null) {
                noDataClickListener.onNoDataClicked();
            }
        }
    }

    public interface OnNoDataClickListener {
        void onNoDataClicked();
    }

}
